Ext.onReady(function() {

    var grid_logs;
    var record_logs;
    var demId;
    var store_logs;
    var jReader_logs
    var xg = Ext.grid;
    var psize_logs = 22;
    var openUrl_logs = basePath
            + 'JarpListener?className=cn.com.jsepc.rep.logs.LogsInfoManage';
    openUrl_logs += '&methodName=getLogsGridData&paramCount=5';

    jReader_logs = new Ext.data.JsonReader({
        root: 'data',
        totalProperty: 'totalCount',
        fields: [{
                name: 'id'
            }, {
                name: 'repid'
            }, {
                name: 'repname'
            }, {
                name: 'roleid'
            }, {
                name: 'log'
            }, {
                name: 'time'
            }, {
                name: 'type'
            }, {
                name: 'text'
            }]
    });

    store_logs = new Ext.data.Store({
        autoLoad: false,
        url: openUrl_logs,
        reader: jReader_logs,
        baseParams: {
            param_0: 0,
            param_1: psize_logs,
            param_2: "",
            param_3: ""
        }
    });

    var loadMarsk = new Ext.LoadMask(document.body, {
        msg: '数据读取中...',
        store: store_logs
    });
    loadMarsk.show();

    store_logs.setDefaultSort('id', 'ASC');
    var sm = new xg.CheckboxSelectionModel({
        header: '',
        singleSelect: true
    });

    var cm = new xg.ColumnModel([
        sm,
        {
            id: 'id',
            name: 'id',
            header: '日志编号',
            sortable: true,
            dataIndex: 'id',
            hidden: true
        },
        {
            name: 'repid',
            header: '指标编号',
            sortable: true,
            dataIndex: 'repid',
            hidden: true
        },
        {
            name: 'repname',
            header: '指标名称',
            sortable: true,
            dataIndex: 'repname'
        },
        {
            name: 'roleid',
            header: '用户',
            sortable: true,
            dataIndex: 'roleid'
        },
        {
            name: 'log',
            header: '日志描述',
            sortable: true,
            dataIndex: 'log'
        },
        {
            name: 'time',
            header: '操作时间',
            sortable: true,
            dataIndex: 'time'
        },
        {
            name: 'type',
            header: '操作类型编号',
            sortable: true,
            dataIndex: 'type',
            hidden: true
        },
        {
            name: 'text',
            header: '操作类型',
            sortable: true,
            dataIndex: 'text'
        }
    ]);

    cm.defaultSortable = true;
    grid_logs = new Ext.grid.GridPanel({
        //autoHeight:true,
        region: 'center',
        title: '日志列表',
        deferredRender: false,
        activeTab: 0,
        split: true,
        //collapsible: true,
        frame: true,
        id: 'chc',
        store: store_logs,
        sm: sm,
        cm: cm,
        viewConfig: {
            forceFit: true
        },
        enableColumnResize: true, //控制列大小调节
        enableColumnMove: true, //控制列的拖动
        // loadMask:true,//数据加载时的遮罩功能 
        stripeRows: true, //显示行的分隔符
        columnLines: true,
        height: screen.height - 320,
        stateful: true,
        stateId: 'grid11',
        bbar: new Ext.PagingToolbar({
            store: store_logs,
            paramNames: {
                start: 'param_0',
                limit: 'param_1'
            },
            emptyMsg: '没有数据需要显示',
            // displayMsg : '显示第{0}到{1}行，共{2}行',
            displayInfo: true,
            pageSize: psize_logs,
            listeners: {
                beforechange: function(bar, params) {
                    bar.store.setBaseParam("param_2", Ext.ComponentMgr.get("KeyWord").getValue());
                    bar.store.setBaseParam("param_3", Ext.ComponentMgr.get("type").getValue());
                }
            }
        })
    });

    //   grid_logs.render('gridDiv_weidu');
    store_logs.load();

    var viewport_weidu = new Ext.Viewport({
        layout: 'border',
        items: [{
                tbar: [{
                        xtype: 'label',
                        text: '请输入指标名称的关键词：'
                    }, {
                        xtype: 'textfield',
                        emptyText: '请输入',
                        id: 'KeyWord'
                    },'开始时间：', {
                        xtype: 'datefield',
                        fieldLabel: '开始时间',
                        name: 'starttime_date',
                        id: 'starttime_date',
                        altFormats: 'Ymd',
                        format: 'Y-m-d',
                        dateFormat:'Ymd',
                        width: 100
                    },'结束时间：', {
                        xtype: 'datefield',
                        fieldLabel: '结束时间',
                        name: 'endtime_date',
                        id: 'endtime_date',
                        altFormats: 'Y-m-d',
                        format: 'Y-m-d',
                        dateFormat:'Ymd',
                        width: 100
                    }, '&nbsp;&nbsp;&nbsp;&nbsp;',{
                        text: '查询',
                        xtype:'button',
                        handler: function() {
                            selectItem_weidu();
                        }
                    }

                ],
                region: 'center',
                deferredRender: false,
                activeTab: 0,
                frame: true,
                layout: 'border',
                items: [grid_logs]
            }]
    })



    //查询
    function selectItem_weidu() {
        var keyword = Ext.ComponentMgr.get("KeyWord").getValue();
         var start = dateFormat(Ext.ComponentMgr.get("starttime_date").getValue());
          var end = dateFormat(Ext.ComponentMgr.get("endtime_date").getValue());
        store_logs.load({
            params: {
                param_2: keyword,
                param_3: start,
                param_4: end
            }
        });
        // Ext.ComponentMgr.get("KeyWord").setValue("");
    }
    
    function dateFormat(value){ 
    if(null != value){ 
        return Ext.util.Format.date(new Date(value),'Ymd'); 
    }else{ 
        return null; 
    } 
} 

});


